<template>
	<view>
		<!-- 
		<image class="bgs"
			src="https://phantombody.oss-cn-shanghai.aliyuncs.com/05efac942e35d4f935dbd6c9a17673707bcb9b2dbd8fe230f691434d7f3b56d4.jpg">
		</image>
		<view class="btns" @click="scanCode()">扫码预约</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		onShow() {
			// if (!uni.getStorageSync('accessToken')) {
			// 	uni.navigateTo({
			// 		url: '/pages/login/index'
			// 	})
			// } else {
			// 	this.scanCode()
			// }
		},
		onLoad() {
			if (!uni.getStorageSync('accessToken')) {
				uni.navigateTo({
					url: '/pages/login/index'
				})
			} else {
				this.scanCode()
			}
		},
		methods: {
			scanCode() {
				let that = this
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						// {"store_id":3,"dev_sn":"10000000668df2e3","type":1}
						var data = JSON.parse(res.result)
						if (data.type == 1) {
							// 创建订单
							uni.navigateTo({
								url: '/pages/mine/reserve?storeId=' + data.store_id,
							})

						} else if (data.type == 2) {
							// data.id
							var orderId = data.id
							// 
							that.ran
								.request('/app-api/system/user-model-order/bind', {
									"id": orderId
								}, 'PUT')
								.then(res => {
									console.log('getStoreInfo orderId', res);
									if (res.code == 200) {
										// 表示绑定成功
										uni.navigateTo({
											url: '/pages/mine/reserve?storeId=' + res.data
												.storeId + "&orderId=" + orderId,
										})
									} else {
										uni.showToast({
											title: res.msg,
											duration: 2000
										});
										uni.reLaunch({
											url: '/pages/3d/index'
										})
									}
								});
							// 绑定订单

						}
					},
					fail(err) {
						uni.reLaunch({
							url: '/pages/3d/index'
						})
					}
				})

			}
		}
	}
</script>
<style lang="scss">
	.bgs {
		width: 100vw;
		height: 100vh;
		display: block;
		position: absolute;
		top: 0;
		left: 0;
		z-index: -1;
	}

	.btns {
		width: 450rpx;
		margin-top: 60vh;
		top: 50%;
		left: 50%;
		margin-left: 150rpx;
		line-height: 90rpx;
		height: 90rpx;
		color: #fff;
		background: #836FFE;
		text-align: center;
		border-radius: 40rpx;
		// position: relative;
		z-index: 999999999999;

	}
</style>